package com.macro.client.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.macro.client.dto.ProductDto;
import com.macro.client.service.HomeService;
import com.macro.mall.mapper.PmsBrandMapper;
import com.macro.mall.mapper.PmsProductMapper;
import com.macro.mall.model.HomeContentResult;
import com.macro.mall.model.PmsBrand;
import com.macro.mall.model.PmsBrandExample;
import com.macro.mall.model.PmsProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName HomeServiceImpl
 * @Description 描述
 * @Author bai
 * @Date 2024/10/22 10:51
 */

@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private PmsBrandMapper pmsBrandMapper;

    @Autowired
    private PmsProductMapper pmsProductMapper;


    @Override
    public HomeContentResult getHomeContent() {
        HomeContentResult homeContentResult = new HomeContentResult();
        homeContentResult.setBrandList(pmsBrandMapper.selectByExample(new PmsBrandExample()));
        return homeContentResult;
    }

    @Override
    public PmsBrand detail(Integer id) {
        PmsBrand pmsBrand = pmsBrandMapper.selectByPrimaryKey(Long.valueOf(id));
        return pmsBrand;
    }

    @Override
    public PageInfo<PmsProduct> fetchBrandProductList(ProductDto productOfBrandRequest) {
        PageHelper.startPage(productOfBrandRequest.getPageNum(),productOfBrandRequest.getPageSize());
        List<PmsProduct> listByBrandId = pmsProductMapper.getListByBrandId(productOfBrandRequest.getBrandId());
        PageInfo<PmsProduct> pmsProductPageInfo = new PageInfo<>(listByBrandId);
        return pmsProductPageInfo;
    }


}
